home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994…tember: Reference Library / Dev.CD Sep 94.toast / Periodicals / develop / develop Issue 18 / develop 18 code / OSA Sample / Sources / ListOfLongs.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-28  |  2.8 KB  |  117 lines  |  [TEXT/MPS ]

  1.  
  2. /*
  3.     File:        ListOfLongs.h
  4.  
  5.     Contains:    TListOfLongs interface
  6.  
  7.     Developed by:    
  8.         
  9.         Paul G Smith (commstalk hq & Full Moon Software, Inc)
  10.         
  11.         you can leave messages at (UK): 0727 844232; (US): 408 253 7199
  12.         BUT I prefer to be contacted by e-mail
  13.         AppleLink:     SMITH.PG
  14.         Internet:     SMITH.PG@applelink.apple.com
  15.         
  16.         "SimpliFace" Sample code to accompany develop article
  17.         on techniques for embedding scripts in applications.
  18.  
  19.  
  20.     Ordered and un-ordered lists of long integers
  21.  
  22. */
  23.  
  24. #ifndef __LISTOFLONGS__
  25. #define __LISTOFLONGS__
  26.  
  27.  
  28. #ifndef __MEMORY__
  29. #include <Memory.h>
  30. #endif
  31.  
  32.  
  33.  
  34.  
  35.  
  36. /**********************************************************************
  37. ** class TListOfLongs
  38. **     Sorted list of long integers (for un-ordered applications)
  39. ***********************************************************************/
  40.  
  41. class TListOfLongs
  42. {    
  43. public:
  44.                     TListOfLongs(void);        // constructor
  45.                     TListOfLongs(const TListOfLongs&);
  46.                     ~TListOfLongs(void);    // destructor
  47.     TListOfLongs&    operator=(const TListOfLongs&);
  48.     
  49.             Handle    GetData(void);                // saves data to handle
  50.             void    SetData(Handle h);            // loads data from handle
  51.     
  52.             long    CountElements(void);
  53.     virtual OSErr    InsertElement(long val);
  54.             void    DeleteElement(long val);
  55.             long    GetElement(long index);
  56.     virtual long    FindElement(long val);         // returns index, or 0 if not found
  57.     
  58. protected:
  59.     long            fNumItems;
  60.     Handle            fDataHandle;
  61.     
  62.             OSErr    ExpandDataHandle(long numLongs);
  63.             OSErr    ShrinkDataHandle(long numLongs);    
  64. };
  65.  
  66.  
  67.  
  68. inline long TListOfLongs::CountElements(void)
  69. {
  70.     return fNumItems;
  71. }
  72.  
  73.  
  74.  
  75. /**********************************************************************
  76. ** class TOrderedListOfLongs
  77. **     Un-sorted list of long integers (for ordered applications)
  78. ***********************************************************************/
  79.  
  80. class TOrderedListOfLongs : public TListOfLongs
  81. {
  82. public:
  83.                             TOrderedListOfLongs(void);        // constructor
  84.                             TOrderedListOfLongs(const TListOfLongs&);
  85.                             ~TOrderedListOfLongs(void);    // destructor
  86.     TOrderedListOfLongs&    operator=(const TOrderedListOfLongs&);
  87.     
  88.     virtual OSErr    InsertElement(long val);
  89.             OSErr    InsertElementAt(long val, long index);
  90.     virtual long    FindElement(long val);         // returns index, or 0 if not found
  91. };
  92.  
  93.  
  94. /**********************************************************************
  95. ** class TStackOfLongs
  96. **     Un-sorted stack of long integers (for ordered applications)
  97. ***********************************************************************/
  98.  
  99. class TStackOfLongs : public TListOfLongs
  100. {
  101. public:
  102.                             TStackOfLongs(void);        // constructor
  103.                             TStackOfLongs(const TListOfLongs&);
  104.                             ~TStackOfLongs(void);    // destructor
  105.     TStackOfLongs&            operator=(const TStackOfLongs&);
  106.  
  107.             OSErr    PushElement(long val);
  108.             OSErr    PopElement(long *val);
  109.     
  110.     // don't call these functions:
  111.     virtual OSErr    InsertElement(long val);
  112.     virtual long    FindElement(long val);     
  113. };
  114.  
  115.  
  116. #endif
  117.